from system.action import Action
import time

class TestAction(Action):
    def run(self, args):
        num = args.get('num',100)
        self.log('running', num, 'jobs')
        workers = [self.object.runAction("worker.worker") for i in range(num)]
        
        start = time.time()
        defers = [self.object.deferRpc(worker,"work",num = i) for i, worker in enumerate(workers)]
        results = [defer() for defer in defers]
        self.log("deferred", time.time() - start)
        
        start = time.time()
        results = [self.object.callRpc(worker,"work",num = i) for i, worker in enumerate(workers)]
        self.log("direct", time.time() - start)
